package fixmodel.adapter;

import fixmodel.base.Quack;
import fixmodel.entity.Goose;
import fixmodel.observable.Observable;
import fixmodel.observable.Observer;

/**使用适配器模式: 大鹅适配器 将鹅适配为鸭子
 * @author yaojianfeng
 */
public class GooseAdapter implements Quack {
    private Observable observable;

    private Goose goose;
    /**
     * 当调用quack()方法时,会被委托到鹅的honk()方法.
     */
    @Override
    public void quack() {
        goose.honk();
        notifyObservers();
    }

    public GooseAdapter() {

    }

    /**
     * 构造器需要传入适配的鹅对象
     * @param goose 鹅对象
     */
    public GooseAdapter(Goose goose) {
        this.goose = goose;
        observable =new Observable(this);
    }

    public Goose getGoose() {
        return goose;
    }

    public void setGoose(Goose goose) {
        this.goose = goose;
    }

    /**
     * 注册方法
     *
     * @param observer 被观察者
     */
    @Override
    public void registerObserver(Observer observer) {
        observable.registerObserver(observer);

    }

    /**
     * 通知观察者
     */
    @Override
    public void notifyObservers() {
        observable.notifyObservers();
    }
}
